package com.falcon.modules.domain.result;


import com.falcon.modules.domain.dto.User;
import lombok.Data;
import org.springside.modules.utils.mapper.JsonMapper;

@Data
public class WebResult<T> {
    private static final int SUCCESS = 200;
    private static final int SERVER_ERROR = 500;
    private static final int CLIENT_ERROR = 400;

    private int status;
    private String msg;
    private T data;

    private WebResult(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static <T> WebResult<T> success(T data) {
        return new WebResult(SUCCESS, "成功", data);
    }

    public static <T> WebResult<T> clientError(String msg) {
        return new WebResult<T>(CLIENT_ERROR, msg, null);
    }

    public static <T> WebResult<T> servertError(String msg) {
        return new WebResult<T>(SERVER_ERROR, msg, null);
    }


    public static void main(String[] args) {
        User user=new User();
        user.setId(12341234L);
        user.setName("fy");
        System.out.println(JsonMapper.INSTANCE.toJson(WebResult.success(user)));
    }
}
